<!--
  ~ This program is part of the OpenLMIS logistics management information system platform software.
  ~ Copyright © 2013 VillageReach
  ~
  ~ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  ~  
  ~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
  ~ You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org. 
  -->

<div>
  <h2 id="warehouseLoadAmountLabel" openlmis-message="label.warehouse.load.amount"></h2>


  <div class="alert alert-info" ng-show="message"><span openlmis-message="message"></span></div>
  <div ng-show="!message">
    <div class="info-box">
      <div class="row-fluid">
        <div class="span3">
          <strong id="deliveryZoneLabel" openlmis-message="label.delivery.zone"> </strong> :&nbsp;<span id="deliveryZoneName" ng-bind="deliveryZone.name"></span>
        </div>
        <div class="span3">
          <strong id="programLabel" openlmis-message="label.program"></strong> :&nbsp;<span id="programName" ng-bind="program.name"></span>
        </div>
        <div class="span3">
          <strong id="periodLabel" openlmis-message="label.period"> </strong> :&nbsp;<span id="periodName" ng-bind="period.name"></span>
        </div>
      </div>
    </div>
    <div class="geo-zone-facility-list">
      <h3><span id="deliveryZoneNameLabel" ng-bind="deliveryZone.name"></span>&nbsp;<span id="totalLabel" openlmis-message="label.total"></span></h3>

      <div>

        <div class="facilities-isa-amount-table" ng-model="sortedGeoZoneKeys[0]">
          <table class="table table-bordered table-striped aggregate-table" id="aggregateTable">
            <thead ng-model="facilityMap[sortedGeoZoneKeys[0]]">
            <tr>
              <th></th>
              <th></th>
              <th class="main-heading"
                  ng-repeat="productGroup in facilityMap[sortedGeoZoneKeys[0]][0].supportedPrograms[0].sortedProductGroup"
                  colspan="{{facilityMap[sortedGeoZoneKeys[0]][0].supportedPrograms[0].programProductMap[productGroup].length}}">
                <span id="productGroupAggregated{{$index}}" ng-bind="productGroup"></span>
              </th>
            </tr>
            <tr>
              <th>
                <span id="geoZoneLevelName" ng-bind="geoZoneLevelName"></span>
              </th>
              <th>
                <span id="aggregatePopulationLabel" openlmis-message="label.population"></span>
              </th>
              <th ng-repeat="programProduct in getProgramProducts(facilityMap[sortedGeoZoneKeys[0]][0])">
                <span id="aggregateProductName{{$index}}" ng-bind="programProduct.product.primaryName"></span>
              </th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="geoZoneName in sortedGeoZoneKeys" >
              <td>
                <span id="geoZoneName{{$index}}" ng-bind="geoZoneName"></span>
              </td>
              <td>
                <span id="populationForGeoZone{{$index}}" ng-bind="aggregateMap[geoZoneName].totalPopulation"></span>
              </td>
              <td ng-repeat="programProduct in getProgramProductsForAggregateRow(geoZoneName)">
                <span id="productIsaForGeoZone{{$parent.$index}}{{$index}}" ng-bind="programProduct.isaAmount"></span>
              </td>
            </tr>
            <tr>
              <td>
                <span id="zoneTotalLabel" openlmis-message="label.zone.total"></span>
              </td>
              <td>
                <span id="zonesPopulationTotal" ng-bind="zonesTotal.totalPopulation"></span>
              </td>
              <td ng-repeat="productIsa in getProgramProductsForAggregateRow(geoZoneName,true)">
                <span id="productIsaAggregate{{$index}}"ng-bind="productIsa.isaAmount"></span>
              </td>
            </tr>
            </tbody>
          </table>
        </div>

      </div>
    </div>

    <div class="geo-zone-facility-list" ng-repeat="geoZoneName in sortedGeoZoneKeys">
      <h3><span id="geoZoneTitle{{$index}}" ng-bind="geoZoneName"></span></h3>


      <div class="facilities-isa-amount-table">
        <table class="table table-bordered table-striped" id="geoZone{{$index}}">
          <thead ng-model="facilityMap[geoZoneName]">
          <tr>
            <th></th>
            <th></th>
            <th class="main-heading"
                ng-repeat="productGroup in facilityMap[geoZoneName][0].supportedPrograms[0].sortedProductGroup"
                colspan="{{facilityMap[geoZoneName][0].supportedPrograms[0].programProductMap[productGroup].length}}">
              <span id="productGroup{{$parent.$index}}{{$index}}" ng-bind="productGroup"></span>
            </th>
          </tr>
          <tr>
            <th>
              <span id="facilityLabel{{$index}}" openlmis-message="label.facility"></span>
            </th>
            <th>
              <span id="populationLabel{{$index}}" openlmis-message="label.population"></span>
            </th>
            <th ng-repeat="programProduct in getProgramProducts(facilityMap[geoZoneName][0])">
              <span id="product{{$parent.$index}}{{$index}}" ng-bind="programProduct.product.primaryName"></span>
            </th>
          </tr>
          </thead>
          <tbody>
          <tr ng-repeat="facility in facilityMap[geoZoneName]">
            <td>
              <span id="facilityName{{$parent.$index}}{{$index}}"ng-bind="facility.name"></span>
              <span id="facilityCode{{$parent.$index}}{{$index}}"ng-bind="facility.code"></span>
            </td>
            <td>
              <span id="population{{$parent.$index}}{{$index}}" ng-bind="facility.catchmentPopulation"></span>
            </td>
            <td ng-repeat="programProduct in getProgramProducts(facility)">
              <span id="isaAmount{{$parent.$parent.$index}}{{$parent.$index}}{{$index}}" ng-bind="programProduct.isaAmount"></span>
            </td>
          </tr>
          <tr>
            <td>
              <span id="geoZoneNameLabel{{$index}}" ng-bind="geoZoneName"></span>
              <span id="totalLabel{{$index}}" openlmis-message="label.total"></span>
            </td>
            <td>
              <span id="population{{$index}}" ng-bind="aggregateMap[geoZoneName]['totalPopulation']"></span>
            </td>
            <td ng-repeat="programProduct in getProgramProductsForAggregateRow(geoZoneName)">
              <span id="isaAmountTotal{{$parent.$index}}{{$index}}"ng-bind="programProduct.isaAmount"></span>
            </td>
          </tr>
          </tbody>
        </table>
      </div>


    </div>
  </div>
</div>